home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / DPMI_UTL / REALIN / SIMRMI.PAS < prev   
Pascal/Delphi Source File  |  1992-03-09  |  5KB  |  150 lines

  1.  
  2.  
  3. {Simulate ReadMode interrupt using the DPMI. Based on SIMRMI in C from
  4. the Microsoft DDK Dept.
  5.  
  6.  
  7. Rex K. Perkins, CIS 70651,1611
  8.  
  9.  
  10. 6th March 1992}
  11.  
  12.  
  13.  
  14. Unit SimRMI;
  15.  
  16. Interface
  17.  
  18. Uses WinProcs,WinTypes,Debug;
  19.  
  20. Type  PRealModeRecord=^TRealModeRecord;
  21.       TRealModeRecord= {Real Mode register record for DPMI services}
  22.                       Record
  23.                         EDI:LongInt;         {Register EDI}
  24.                         ESI:LongInt;         {Register ESI}
  25.                         EBP:LongInt;         {Register EBP}
  26.                         Reserved:LongInt;    {Reserved}
  27.                         EBX:LongInt;         {Register EBX}
  28.                         EDX:LongInt;         {Register EDX}
  29.                         ECX:LongInt;         {Register ECX}
  30.                         EAX:LongInt;         {Register EAX}
  31.  
  32.                         Flags:Word;          {Register Flags}
  33.                         ES:Word;             {Register ES}
  34.                         DS:Word;             {Register DS}
  35.                         FS:Word;             {Register FS}
  36.                         GS:Word;             {Register GS}
  37.                         IP:Word;             {Register IP}
  38.                         CS:Word;             {Register CS}
  39.                         SP:Word;             {Register SP}
  40.                         SS:Word              {Register SS}
  41.                       End;
  42.  
  43. Const
  44.              {Pass this constant if you don't need to define the registers}
  45.         DontCareRMR:TRealModeRecord=(
  46.                                      EDI:0;
  47.                                      ESI:0;
  48.                                      EBP:0;
  49.                                      Reserved:0;
  50.                                      EBX:0;
  51.                                      EDX:0;
  52.                                      ECX:0;
  53.                                      EAX:0;
  54.                                      Flags:0;
  55.                                      ES:0;
  56.                                      DS:0;
  57.                                      FS:0;
  58.                                      GS:0;
  59.                                      IP:0;
  60.                                      CS:0;
  61.                                      SP:0;
  62.                                      SS:0);
  63.  
  64.  
  65.  
  66.   Function SimRealModeInt(IntNumber:Byte; RealModeRecord:PRealModeRecord):Boolean;
  67.  
  68.     {Simulate a call to the spectified real mode interrupt. The real mode registers
  69.      are defined in RealModeRecord, and are returned in this same structure. Returns
  70.      False if there was an error.}
  71.  
  72.   Function CheckISRInstalled(IntVec:Byte):Boolean;
  73.  
  74.     {Check that there is an Interrupt Service Routine installed. Returns true if a non-zero segment
  75.      was found in the specified ISR vector. If returns False, there is not a valid
  76.      address in the interrupt vector so the interrupt should not be called}
  77.  
  78.  
  79.  
  80. Implementation
  81.  
  82.  
  83.  
  84.  
  85.   Function SimRealModeInt(IntNumber:Byte; RealModeRecord:PRealModeRecord):Boolean;
  86.  
  87.     {Simulate a call to the spectified real mode interrupt. The real mode registers
  88.      are defined in RealModeStruct, and are returned in this same structure. Returns
  89.      False if there was an error.}
  90.  
  91.   Var Status:Boolean;
  92.  
  93.   Begin
  94.     ASM
  95.         push di
  96.         push es
  97.  
  98.         mov  bh,00               {For DOSX to reset the int controller and A20 line.  Windows ingores it.}
  99.         mov  bl,IntNumber        {Tell DPMI which interrupt to simulate}
  100.         xor  cx,cx               {0 bytes to copy to real mode stack}
  101.         les  di,RealModeRecord   {Get the real mode structure}
  102.         mov  ax,$0300            {0300h is simulate real mode interrupt}
  103.         int  31h
  104.  
  105.         jc   @Error              {The carry flag was set, so there was an error}
  106.         mov  Status,True         {Return no error}
  107.         jmp  @AllDone
  108.  
  109.       @Error:
  110.         mov  Status,False        {Return false indicating an error}
  111.  
  112.       @AllDone:
  113.         pop  es
  114.         pop  di
  115.     End
  116.   End;
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.   Function CheckISRInstalled(IntVec:Byte):Boolean;
  124.  
  125.     {Check that there is an ISR installed. Returns true if a non-zero segment
  126.      was found in the specified ISR vector. If returns False, there is not a valid
  127.      address in the interrupt vector so the interrupt should not be called}
  128.  
  129.   Var ISRSegment:Word;
  130.  
  131.   Begin
  132.     ASM
  133.       mov     ax,0200h       {DPMI Get Real Mode Interrupt Vector}
  134.       mov     bl,IntVec      {Check for the specified interrupt}
  135.       int     31h            {Call DPMI}
  136.       mov     ISRSegment,cx  {CX holds the ISR segment}
  137.     End;
  138.  
  139.     If ISRSegment<>0 Then {The Int vector is not 0 so there must be an ISR}
  140.       CheckISRInstalled:=True
  141.     Else
  142.       CheckISRInstalled:=False
  143.   End;
  144.  
  145.  
  146.  
  147. Begin
  148. End.
  149.  
  150.